package com.example.scanningshardutils.utils;

import android.content.Context;
import android.content.SharedPreferences;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;

import com.example.scanningshardutils.R;


public class ExitEditorDialog extends LinearLayout {

    public ExitEditorDialog(Context context) {
        super(context);
        init(context, null);
    }

    public ExitEditorDialog(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init(context, attrs);
    }

    public ExitEditorDialog(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context, attrs);
    }

    SharedPreferences setting;

    private void init(final Context context, AttributeSet attrs) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.exit_dialog_layout, this);
        setting = context.getSharedPreferences("AppNAME", 0);
        Boolean user_first = setting.getBoolean("FIRST", true);
        if (user_first) {//第一次
            findViewById(R.id.layouttt).setVisibility(VISIBLE);
        } else {
            if (null != listener) listener.doConfirm();
            findViewById(R.id.layouttt).setVisibility(GONE);
        }
        inflate.findViewById(R.id.xieyi).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
        inflate.findViewById(R.id.yinsi).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                setting.edit().putBoolean("FIRST", false).commit();
            }
        });
        inflate.findViewById(R.id.tv_right).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (null != listener) listener.doConfirm();
                findViewById(R.id.layouttt).setVisibility(GONE);
                setting.edit().putBoolean("FIRST", false).commit();
            }
        });
    }

    public ClickListener listener;

    public ClickListener getListener() {
        return listener;
    }

    public void setListener(ClickListener listener) {
        this.listener = listener;
    }

    public interface ClickListener {

        public void doConfirm();

    }


}